package com.example.kafkatest.controller;

import com.alibaba.fastjson.JSON;
import com.yun.util.RestResult;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: fxy
 * @Date: 2023/02/03/10:32
 * @Description:
 */
@RestController
@RequestMapping("/kafkaTest")
public class KafkaController {

    @Resource
    KafkaTemplate<String,Object> kafkaTemplate;

    @PostMapping("/sendMessage")
    public RestResult<Integer> sendMessage(@RequestBody Object message){
        ListenableFuture release_meter_data = kafkaTemplate.send("RELEASE_METER_DATA", JSON.toJSONString(message));
        return RestResult.success(1);
    }
}
